<template>
  <component
    v-if="id && visible"
    class="d-view"
    :is="tabName"
    :crmType="crmType"
    :type="type"
    :id="id"
    :isSeas="isSeas"
    :listenerIDs="listenerIDs"
    :noListenerIDs="noListenerIDs"
    @handle="detailHandle"
    @hide-view="hiddenView"
  >
  </component>
</template>

<script type="text/javascript">
import { getMaxIndex } from "@/utils/index";
import ClueDetail from "../clue/ClueDetail";
import CustomerDetail from "../customer/CustomerDetail";
// import OkCustomerDetail from "../okCustomer/OkCustomerDetail";
import ContactsDetail from "../contacts/ContactsDetail";
import BusinessDetail from "../business/BusinessDetail";
import ContractDetail from "../contract/ContractDetail";
import ExpenceDetail from "../contract/ContractDetail"; // 共用合同详情
import InvoiceDetail from "../contract/ContractDetail"; // 共用合同详情
import WoDetail from "../wo/WoDetail";
import CompleteDetail from "../complete/CompleteDetail";
import ProductDetail from "../product/ProductDetail";
import MoneyDetail from "../money/MoneyDetail";

export default {
  name: "c-r-m-all-detail", //详情
  components: {
    ClueDetail,
    CustomerDetail,
    // OkCustomerDetail,
    ContactsDetail,
    BusinessDetail,
    ContractDetail,
    ExpenceDetail,
    InvoiceDetail,
    WoDetail,
    CompleteDetail,
    ProductDetail,
    MoneyDetail
  },
  watch: {
    crmType(type) {
      this.setCrmType();
    },
    id(v) {
      this.setCrmType();
    }
  },
  computed: {},
  data() {
    return {
      tabName: "" // 组件名
    };
  },
  props: {
    /** 模块ID */
    id: [String, Number],
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ""
    },
    // 区分 私库 成交客户 公海
    type: {
      type: String,
      default: ""
    },
    visible: {
      type: Boolean,
      default: false
    },
    // 监听的dom 进行隐藏详情
    listenerIDs: {
      type: Array,
      default: () => {
        return ["crm-main-container"];
      }
    },
    // 不监听
    noListenerIDs: {
      type: Array,
      default: () => {
        return [];
      }
    },
    noListenerClass: {
      type: Array,
      default: () => {
        return ["el-table__body"];
      }
    },
    // 是否是公海
    isSeas: {
      type: Boolean,
      default: false
    }
  },
  mounted() {
    console.log(this.type, "type");
    if (this.visible) {
      document.body.appendChild(this.$el);
      this.$el.style.zIndex = getMaxIndex();
    }
  },
  methods: {
    hiddenView() {
      this.$emit("update:visible", false);
    },
    // 选择详情组件弹窗
    setCrmType() {
      console.log(this.crmType, "详情组件弹窗");
      if (this.crmType == "leads") {
        this.tabName = "clue-detail";
      } else if (
        this.crmType == "customer" ||
        this.crmType == "okcustomer" ||
        this.crmType == "ideacustomer"
      ) {
        this.tabName = "customer-detail";
      } else if (this.crmType == "contacts") {
        this.tabName = "contacts-detail";
      } else if (this.crmType == "wo") {
        this.tabName = "wo-detail";
      } else if (this.crmType == "complete") {
        this.tabName = "complete-detail";
      } else if (this.crmType == "business") {
        this.tabName = "business-detail";
      } else if (this.crmType == "contract") {
        this.tabName = "contract-detail";
      } else if (this.crmType == "expence") {
        this.tabName = "expence-detail";
      } else if (this.crmType == "invoice") {
        this.tabName = "invoice-detail";
      } else if (this.crmType == "product") {
        this.tabName = "product-detail";
      } else if (this.crmType == "receivables") {
        this.tabName = "money-detail";
      }
    },
    /**
     * 详情操作
     */
    detailHandle(data) {
      this.$emit("handle", data);
    }
  },
  destroyed() {
    // remove DOM node after destroy
    if (this.$el && this.$el.parentNode) {
      this.$el.parentNode.removeChild(this.$el);
    }
  }
};
</script>
<style lang="scss" scoped>
.full-container {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: auto;
  margin: 0;
  background-color: rgba(0, 0, 0, 0.3);
}

.d-view {
  position: fixed;
  width: 950px;
  top: 0px;
  bottom: 0px;
  right: 0px;
}
</style>
